// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
// mod mouse;
mod core;
use tauri::Manager;

use core::{
    device::start_device_listening,
};

#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_store::Builder::new().build())
        .plugin(tauri_plugin_http::init())
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_process::init())
        .plugin(tauri_plugin_os::init())
        .plugin(tauri_plugin_opener::init())
        .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
            let windows = app.webview_windows();
            // 优先显示已存在的home窗口
            for (name, window) in windows {
                if name == "home" {
                    window.show().unwrap();
                    window.unminimize().unwrap();
                    window.set_focus().unwrap();
                    break;
                }
            }
        }))
        .invoke_handler(tauri::generate_handler![
            greet,
            start_device_listening
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
